package com.heima.wemedia.controller.v1;

import com.heima.apis.wemedia.WmUserControllerApi;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmUserDto;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    WmUserService wmUserService;

    /**
     * 查询
     *
     * @param name
     * @return
     */
    @Override
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable("name") String name) {

        WmUser wmUser = wmUserService.findByName(name);
        return wmUser;
    }

    /**
     * 新增
     *
     * @param wmUser
     * @return
     */
    @PostMapping("/save")
    @Override
    public WmUser save(@RequestBody WmUser wmUser) {

        WmUser wmUserNew = wmUserService.saveWm(wmUser);
        return wmUserNew;
    }

    /**
     * 根据id查询自媒体用户
     *
     * @param id 自媒体用户ID
     * @return
     */
    @GetMapping("/findOne/{id}")
    @Override
    public WmUser findWmUserById(@PathVariable("id") Integer id) {
        return wmUserService.getById(id);
    }


}
